from lxml import etree
import urllib.request

url="https://list.jd.com/list.html?cat=652&cu=true&utm_source=&utm_medium=tuiguang&utm_campaign=t_2031180302_&utm_term=fa5524d9222545bbacec745603920dae"

# tree=etree.
# //div/ul/li//div/a/em

headers = {
    'authority': 'api.m.jd.com',
    'accept': 'application/json',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-type': 'application/x-www-form-urlencoded',
    'cookie': 'unpl=JF8EAK1nNSttDxtQARgHThoTSF5QW1lbGEdROzUDUVlfSlYNGANOQkR7XlVdWBRKHx9tZhRVW1NLXQ4aACsSE3teVVxdCEIWAW5kNWRaWEIZRElPKxEQe11Vbl0OSBEEa2cMXVxYT1QFGAodFhVMWFZWbQl7EANmVzVkWFhKVAQTABobFHtcZFxdCUoRB2lmA1xtEyVVSBsEGBQXT11dV1wITxcDbG8DUFhfTlYNKwMrEQ; __jdu=17276518801511297546439; shshshfpa=58996440-83da-08da-d733-8f233f0879d5-1727651883; shshshfpx=58996440-83da-08da-d733-8f233f0879d5-1727651883; areaId=19; __jdv=29846306|lianmeng__10__kong|t_2031180302_|tuiguang|fa5524d9222545bbacec745603920dae|1727652369705; jsavif=1; token=595f4095ed14b003c13e954b40f7beb5,2,959825; ipLoc-djd=19-1601-50258-129167; 3AB9D23F7A4B3CSS=jdd03Z6BNZJQH5KZBU4465VHC6H3KPPRLOVBBFX2G5I4A5RNP3M5QB7A2SBESSQ2YGBBFB7KK7XGNH5LB2M6QEXAYJL3OQIAAAAMSIISOC5IAAAAADLYPNOFWQYHUKIX; _gia_d=1; wlfstk_smdl=uoju96is2mam59rj8vcz495d644ylo7g; _pst=jd_SJdCPdjjtDom; logintype=wx; unick=%E6%88%BF%E6%97%AD%E9%9B%AAzp; pin=jd_SJdCPdjjtDom; npin=jd_SJdCPdjjtDom; thor=55C3D95F479481AFEA2EAF1F2CD17CB7166C362D789350DEA2DAD66B3D2C144440B31733E3C66F47F974DF106DD1DCA366AE2D8E2C0DE53F50FFE1C4CC48313E88ECA7CAC2BF2333E7D667D004C6F8E41F94757C46146423EC3C0B0B121724699583561126D449060A0F75F95043631F406DD4986E0FDDB1D7E3F5B7473A237569E18EADFE80C8752D760152C4256E54AD544D7CD3F362E7A0FA4C91192DC908; flash=3_4mgZkDqAEK3M0wnync-McWM2Dig3MIV4Z0lTy4VoQvGMEoBykEXkKmm98cX7yEqdWqdg6NDm3eBLJ4UgEf1nGuKbTkK1ekHgtOUiT0DD6tbh0-jdT-Rgzu3xjq7bNaQTsNYDbGobDQU0jpMKijYZU-s7uAakz5F3zxm1KOwshV**; _tp=DwbXOH6vKtHkp2gph%2FcPkA%3D%3D; pinId=sT2WcEpiuEgv39JcwxucDg; __jda=29846306.17276518801511297546439.1727651880.1727651883.1727686162.2; __jdc=29846306; __jdb=29846306.10.17276518801511297546439|2.1727686162; shshshfpb=BApXSFNMtQfdAb8pQcZ3mbmX65lSEzsgPBmUkH6xo9xJ1Mozb5IC2; 3AB9D23F7A4B3C9B=Z6BNZJQH5KZBU4465VHC6H3KPPRLOVBBFX2G5I4A5RNP3M5QB7A2SBESSQ2YGBBFB7KK7XGNH5LB2M6QEXAYJL3OQI',
    'origin': 'https://list.jd.com',
    'referer': 'https://list.jd.com/',
    'sec-ch-ua': '"Chromium";v="109", "Not_A Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
    'x-referer-page': 'https://list.jd.com/list.html',
    'x-rp-client': 'h5_1.0.0',
}

request=urllib.request.Request(url=url,headers=headers)

response=urllib.request.urlopen(request)

content=response.read().decode('utf-8')
# with open('jingdong.html','w',encoding='utf-8') as f:
#     f.write(content)

tree=etree.HTML(content)

list=tree.xpath('//li/div//a/em/text()')

print(list)
print(len(list))